package com.cino.Thread;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class threadPool {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(4);

        // 提交 Runnable 任务
        executorService.submit(() -> {
            System.out.println("Running task 1");
        });

        // 提交 Callable 任务
        Future<Integer> future = executorService.submit(() -> {
            return 42;
        });

        try {
            System.out.println("Result of task 2: " + future.get());
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }

        // 关闭线程池
        executorService.shutdown();
    }
}
